public class Queue<Item>{
    private Node head;
    private Node last;
    private int N;
    private class Node{
        Item val;
        Node next;
        public Node(){

        }
        public Node(Item val){
            this.val = val;
        }
    }
    public boolean isEmpty(){
        return N==0;
    }
    public int size(){
        return N;
    }
    public void enqueue(Item item){
        //向队尾添加元素
        Node oldlast = last;
        last = new Node(item);
        if(isEmpty()){
            head = last;
        }else{
            oldlast.next = last;
        }
        N++;
    }
    public Item dequeue(){
        //从表头删除元素
        Item item = head.val;
        head = head.next;
        if(isEmpty()) last = null;
        N--;
        return item;
    }
}
